/*
 * @(#)ProductController.java 2021年3月8日
 *
 * Copyright (c) 2010 by rayootech.com. All rights reserved.
 */
package com.nuctech.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.nuctech.common.entity.Product;
import com.nuctech.product.service.ProductService;

import cn.hutool.core.util.StrUtil;

/**
 * 商品接口控制器
 *
 * @author lilu
 * @date 2021年3月8日
 * @since 1.0.0
 */
@RestController
@RequestMapping("/product")
public class ProductController {

	@Autowired
	private ProductService productService;

	/**
	 * 获取商品信息
	 *
	 * @author lilu
	 * @date 2021年3月8日 下午3:27:09
	 * @since 1.0.0
	 *
	 * @param pid
	 * @return
	 */
	@GetMapping("/{pid}")
	public Product product(@PathVariable("pid") Integer pid) {
		return this.productService.findByPid(pid);
	}

	@GetMapping("/api1/{version}")
	public String api1(@PathVariable("version") Integer version) {
		return StrUtil.format("api1,version:{}", version);
	}

	@GetMapping("/api2/{version}")
	public String api2(@PathVariable("version") Integer version) {
		return StrUtil.format("api2,version:{}", version);
	}

	@PostMapping("/reduceInventery")
	public Integer reduceInventery(@RequestParam("pid") Integer pid, @RequestParam("number") Integer number) {
		return this.productService.reduceInventery(pid, number);
	}

}
